<template>
  <div class="searchResult">
    <div class="title">
      <van-nav-bar title="搜索结果页" left-arrow @click-left="onClickLeft">
      </van-nav-bar>
    </div>
    <div v-if="resultList.length !== 0">
      <div class="resultTitle">
        {{ resultTitle }}
      </div>
      <div
        class="content"
        v-for="(item, index) in resultList"
        :key="index"
        @click="resultClick(item.art_id)"
      >
        <h4>{{ item.title }}</h4>
        <div class="cover" v-if="item.cover && item.cover.type > 0">
          <div
            v-for="(item1, index1) in item.cover.images"
            :key="index1"
            class="images"
          >
            <img :src="item1" alt="" />
          </div>
        </div>
        <div class="info">
          <span>{{ item.aut_name }}</span>
          <span>{{ item.collect_count }}评论</span>
          <span>{{ item.pubdate | hmfilter }}</span>
        </div>
        <div class="infoicon">
          <div class="msg">
            <i>
              <van-icon name="records" size="25px" />
            </i>
            <span>{{ item.collect_count }}</span>
          </div>
          <div class="like">
            <i>
              <van-icon name="good-job-o" size="25px" />
            </i>
            <span>点赞</span>
          </div>
          <div class="share">
            <i>
              <van-icon name="share-o" size="25px" />
            </i>
            <span>分享</span>
          </div>
        </div>
      </div>
    </div>
    <div v-else class="nodata">
      <div class="none">暂无数据</div>
    </div>
  </div>
</template>
<script>
import { getResultApi } from '../../api/searchApi'
export default {
  data () {
    return {
      resultTitle: '',
      resultList: [],
      art_id: '',
      // 图片数组
      pics: []
    }
  },
  async created () {
    // console.log('key', this.$route.params.key)
    this.resultTitle = this.$route.params.key
    const res = await getResultApi(this.$route.params.key)
    // this.art_id = res.data.resultList
    this.resultList = res.data.results
    // console.log(this.resultList)
  },
  methods: {
    onClickLeft () {
      // this.$router.push('/search')
      this.$router.back()
    },
    resultClick (id) {
      // 通过文章id 跳转文章详情页面
      this.$router.push(`/detail/${id}`)
      // console.log(id)
    }
  }
}
</script>
<style lang="less" scoped>
.searchResult {
  padding-top: 45px;
  /deep/ .van-nav-bar__content {
    background-color: #3296fa;
  }
  /deep/ .van-nav-bar__title {
    color: #fff;
    font-size: 16px;
  }
  /deep/ .van-icon-arrow-left::before {
    font-size: 22px;
    color: #fff;
  }
  .title {
    position: fixed;
    top: 0;
    left: 0px;
    width: 100%;
    z-index: 100;
  }
  .resultTitle {
    font-size: 12px;
  }
  .content {
    padding: 30px 15px 10px;
    font-size: 16px;
    color: #949494;
    border-bottom: 1px solid #d7d7d7;

    h4 {
      margin: 0;
      padding: 0;
      font-weight: normal;
      color: #363b3e;
    }
    .cover {
      display: flex;
      justify-content: space-around;
      margin-top: 20px;
      .images {
        img {
          width: 100px;
          height: 100px;
        }
      }
    }
    .info {
      margin: 15px 0 10px;
      font-size: 12px;
      color: #b2ada6;
      span:nth-child(2) {
        margin: 0 10px 0;
      }
    }
    .infoicon {
      display: flex;
      justify-content: space-between;
      .msg,
      .like,
      .share {
        display: flex;
        align-items: center;
        justify-content: center;
        i {
          margin-right: 2px;
        }
      }
    }
  }
  .nodata {
    height: 100vh;
    background: #eee;
  }
}
</style>
